package domain;

import java.util.Calendar;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "profile")
public class Profile extends PersistentEntity {

	@OneToOne(mappedBy="profile", fetch = FetchType.EAGER)
	private User user;

	@OneToOne(fetch=FetchType.EAGER)
	@Cascade(value = CascadeType.ALL)
	private LinkedInProfile linkedInProfile = new LinkedInProfile(); 
	//TODO esto no esta bueno, pero sino falla la busqueda cuando un usuario no tiene perfil del linkedin 
	
	@OneToOne(fetch=FetchType.EAGER)
	@Cascade(value = CascadeType.ALL)
	private FacebookProfile facebookProfile = new FacebookProfile(); 
	//TODO esto no esta bueno, pero sino falla la busqueda cuando un usuario no tiene perfil del linkedin
	
	@Column(nullable = false)
	private String studentcode;

	@Column(nullable = false)
	private Date birthdate;

	private String phones;

	private String emails;

	private String experience;

	private String education;

	private String web;

	private String recommendations;

	private Image photo;

	private String title;

	private String actualjob;

	private String links;

	private String extract;

	private String interests;

	private String knowldege;

	@Enumerated
	private Gender gender = Gender.MALE;
	
	@Enumerated
	private MaritalStatus maritalStatus;

	private String address;
	
	public Profile(User user) {
		super();
		this.user = user;
	}
	
	public Profile(User user, String studentcode, Date birthdate, String phones, String personalEmails) {
		super();
		this.user = user;
		this.studentcode = studentcode;
		this.birthdate = birthdate;
		this.phones = phones;
		this.emails = personalEmails;
	}
	
	public Profile(User user, String studentcode, Date birthdate,
			String phones, String personalEmails, String experience, String education,
			String web, String recommendations, Image photo, String title,
			String actualjob, String links, String extract, String interests,
			String knowldege, MaritalStatus maritalstatus, String address) {
		super();
		this.user = user;
		this.studentcode = studentcode;
		this.birthdate = birthdate;
		this.phones = phones;
		this.emails = personalEmails;
		this.experience = experience;
		this.education = education;
		this.web = web;
		this.recommendations = recommendations;
		this.photo = photo;
		this.title = title;
		this.actualjob = actualjob;
		this.links = links;
		this.extract = extract;
		this.interests = interests;
		this.knowldege = knowldege;
		this.maritalStatus = maritalstatus;
		this.address = address;
	}

	// hibernate
	protected Profile() {
	}

	public User getUser() {
		return user;
	}

	public String getStudentcode() {
		return studentcode;
	}

	public Date getBirthdate() {
		return birthdate;
	}
	
	public String getBirthdateString() {
		Calendar cal = Calendar.getInstance();
		cal.setTime(birthdate);
		int monthInt = cal.get(Calendar.MONTH)+1;
		return cal.get(Calendar.DATE) + "/" + monthInt + "/" + cal.get(Calendar.YEAR);
	}
	
	public void setBirthdate(Date birthdate) {
		this.birthdate = birthdate;
	}

	public String getPhones() {
		return phones;
	}
	
	public void setPhones(String phones) {
		this.phones = phones;
	}

	public String getEmails() {
		return emails;
	}
	
	public void setEmails(String emails) {
		this.emails = emails;
	}

	public String getExperience() {
		return experience;
	}

	public String getEducation() {
		return education;
	}

	public void setEducation(String education) {
		this.education = education;
	}

	public String getWeb() {
		return web;
	}

	public String getRecommendations() {
		return recommendations;
	}

	public Image getPhoto(){
		return photo;
	}
	
	public void setPhoto(Image photo){
		this.photo = photo;
	}
	
	public String getTitle() {
		return title;
	}

	public String getActualjob() {
		return actualjob;
	}

	public String getLinks() {
		return links;
	}

	public String getExtract() {
		return extract;
	}

	public String getInterests() {
		return interests;
	}

	public String getKnowldege() {
		return knowldege;
	}

	public Gender getGender() {
		return gender;
	}
	
	public void setGender(Gender gender) {
		this.gender = gender;
	}
	
	public MaritalStatus getMaritalstatus() {
		return maritalStatus;
	}
	
	public void setMaritalstatus(MaritalStatus maritalstatus) {
		this.maritalStatus = maritalstatus;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Override
	public String toString() {
		return "Profile [user=" + user.toString() + ", studentcode=" + studentcode
				+ ", birthdate=" + birthdate + ", phones=" + phones
				+ ", emails=" + emails + ", experience=" + experience
				+ ", education=" + education + ", web=" + web
				+ ", recommendations=" + recommendations + ", photo=" + photo
				+ ", title=" + title + ", actualjob=" + actualjob + ", links="
				+ links + ", extract=" + extract + ", interests=" + interests
				+ ", knowldege=" + knowldege + ", maritalstatus="
				+ maritalStatus + ", address=" + address + "]";
	}

	public void setLinkedInProfile(LinkedInProfile linkedInProfile) {
		this.linkedInProfile = linkedInProfile;
	}

	public LinkedInProfile getLinkedInProfile() {
		return linkedInProfile;
	}

	public void setFacebookProfile(FacebookProfile facebookProfile) {
		this.facebookProfile = facebookProfile;
	}
	
	public FacebookProfile getFacebookProfile() {
		return facebookProfile;
	}

	public void setExperience(String experience) {
		this.experience = experience;
	}

	public void setWeb(String web) {
		this.web = web;
	}

	public void setRecommendations(String recommendations) {
		this.recommendations = recommendations;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setActualjob(String actualjob) {
		this.actualjob = actualjob;
	}

	public void setLinks(String links) {
		this.links = links;
	}

	public void setExtract(String extract) {
		this.extract = extract;
	}

	public void setInterests(String interests) {
		this.interests = interests;
	}

	public void setKnowldege(String knowldege) {
		this.knowldege = knowldege;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((studentcode == null) ? 0 : studentcode.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Profile other = (Profile) obj;
		if (studentcode == null) {
			if (other.studentcode != null)
				return false;
		} else if (!studentcode.equals(other.studentcode))
			return false;
		return true;
	}
	
	

}